<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
    <link crossorigin="anonymous" href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <title>axios创建实例</title>
</head>
<body>
    <div class="container">
        <button class="btn btn-primary">发送GET请求</button>
        <button class="btn btn-warning">发送POST请求</button>
    </div>

    <script>
        const btns = document.querySelectorAll('button');
        
        //-----------------------------------------------------------------------------------------------------
        // 创建实例对象
        const instance = axios.create({
            baseURL: 'http://localhost:53000',
            timeout: 1000,
        });

        // get
        btns[0].addEventListener('click',function() {
            instance.get('/posts/2').then(response => {
                console.log(response);
            })
        });

       


        
    </script>
</body>
</html>